<template>
  <div class="app-container hk-flex-column">
    <div class="hk-flex-column mt20 tab-content">
      <search-form
        :data="queryParams"
        :field-list="filterInfo.fieldList"
        :list-type-info="dictList"
        @handleSearch="handleQuery"
        @handleReset="resetQuery" />

      <hk-table
        :table-data="tableData"
        :table-columns="tableList"
        :selection="false"
        :show-index="false"
        :total="total"
        :rowkey="'id'"
        :loading="loading"
        :table-height="80"
        identifier="dealSituationList"
        operate
        default-expand-all
        :query-params="queryParams"
        :tree-props="{ children: 'assetsDictDataList' }"
        @changePage="getDataList">
        <!-- 操作权限 -->
        <template #operate="scope">
          <el-button v-if="scope.row.sort == 0" size="mini" type="text" @click="handleAdd(scope.row)">新增</el-button>
          <el-button v-if="scope.row.sort != 0" size="mini" type="text" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button v-if="scope.row.sort != 0" size="mini" type="text" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
        <template #name="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </hk-table>
      <add-report ref="editRef" :title="title" @close="handleSubmit" />
    </div>
  </div>
</template>

<script>
import { pageList, deleteItem } from '@/api/specialProject/dict'
import SearchForm from '@/components/HkSearchform/index.vue'
import HkTable from '@/components/Hk-Table/index.vue'
import AddReport from './components/addReport'

export default {
  components: {
    SearchForm,
    HkTable,
    AddReport,
  },
  data() {
    return {
      title: '新增',
      queryParams: {
        current: 1,
        size: 10,
      },
      ids: [],
      total: 0,
      loading: false,
      tableData: [],
      tableList: [
        { label: '字段名称', param: 'name', type: 'slot' },
        { label: '编码', param: 'code' },
        // { label: '操作', param: 'operate', type: 'slot' },
      ],
      filterInfo: {
        fieldList: [{ label: '关键字', type: 'input', field: 'name', placeholder: '请输入字段名称', maxlength: 20 }],
      },
      dictList: {
        typeList: [],
      },
      myData: {},
    }
  },
  created() {
    this.getDataList()
  },
  methods: {
    //  查询列表
    getDataList() {
      this.loading = true
      pageList(this.queryParams).then((res) => {
        this.tableData = res.list
        this.total = res.total
        this.loading = false
      })
    },
    changePage(e) {
      console.log(e)
    },
    //  查询
    handleQuery() {
      this.queryParams.current = 1
      this.getDataList()
    },
    //  重置
    resetQuery() {
      this.queryParams.current = 1
      this.queryParams.size = 10
      this.getDataList()
    },
    // 右侧新增完成
    handleSubmit() {
      this.getDataList()
    },
    // 删除
    handleDelete(row) {
      console.log(row)
      const id = row.id
      var that = this
      this.$modal
        .confirm('是否确认删除所选数据项？')
        .then((res) => {
          deleteItem(id).then((res) => {
            that.$modal.msgSuccess('删除成功')
            that.$nextTick(() => {
              that.handleQuery()
            })
          })
        })
        .catch((error) => {
          console.log(error)
        })
    },
    // 编辑
    handleEdit(row) {
      this.title = '编辑'
      this.$refs.editRef.show(row, true)
    },
    // 新增
    handleAdd(row) {
      this.title = '新增'
      this.$refs.editRef.show(row, false)
    },
  },
}
</script>

<style lang="scss" scoped>
.sm-cg {
  ::-webkit-scrollbar {
    /* 对应纵向滚动条的宽度 */
    width: 6px;
    /* 对应横向滚动条的宽度 */
    height: 6px;
  }

  /* 滚动条上的滚动滑块 */
  ::-webkit-scrollbar-thumb {
    background-color: #d9d9d9;
    border-radius: 32px;
  }

  /* 滚动条轨道 */
  ::-webkit-scrollbar-track {
    background-color: #f3f5fb !important;
    border-radius: 32px;
  }
  /* 滚动条右下角小白块 */
  ::-webkit-scrollbar-corner {
    background: transparent;
  }
}
.cai-gou {
  overflow: auto;
  padding: 0 1.25rem;
}
img {
  width: 50px;
}
.app-container {
  background: #eef0f5 !important;
  padding: 0;
  header {
    padding: 20px;
    background: #fff;
    height: 160px;
    border-radius: 4px;

    .left {
      width: 20%;
      max-width: 250px;
      img {
        width: 100px;
      }
    }
    .total-area {
      margin-left: 5px;
    }
    .tab-bg {
      background: #f3f5fb;
      padding: 22px;
      border-radius: 4px;
      width: 600px;
    }
    .icon {
      align-items: center;
      margin-right: 20px;
      p {
        margin: 0;
        margin-top: 10px;
      }
    }
    .sp-flex {
      span {
        max-width: 90%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      i {
        font-style: normal;
        font-size: 18px;
        color: #333333;
        line-height: 24px;
        font-weight: 600;
      }
    }
    .tab-list {
      height: 100%;
      margin-right: 20px;
    }
  }
}
.tab-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  position: relative;
  background: #fff;
}

#app.dark-theme {
  .app-container header,
  .tab-content {
    background: transparent !important;
    color: #fff;
  }
  .tab-bg {
    background: rgba(59, 139, 255, 0.1) !important;
  }
  .sp-flex i {
    color: #4b6eef !important;
  }
}

.el-row {
  position: absolute;
  right: 20px;
  top: 50px;
}
.total-title {
  margin-bottom: 15px;
  margin-top: 6px;
  line-height: 24px;
}
.font-size16 {
  font-size: 16px;
}
.flex-1 {
  flex: 1;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}
.font-c-blue {
  color: #4b6eef;
  font-size: 36px;
}
.mt-20 {
  margin-top: 20px;
}
::v-deep {
  .content {
    padding-bottom: 0;
  }
}
</style>
